package com.xinghou.platform.service.main.impl;

import com.xinghou.platform.dao.main.*;
import com.xinghou.platform.model.main.*;
import com.xinghou.platform.service.main.PhotoDataProcessService;
import com.xinghou.platform.util.DateUtils;
import com.xinghou.platform.util.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 图像数据存储处理
 * @author xuzhen
 *
 */
@Service("photoDataProcessService")
public class PhotoDataProcessServiceImpl implements PhotoDataProcessService{
	@Override
	public int updatePhotoHeadData(String userid, Map<String, String> data) throws DataAccessException {
		return 0;
	}

	@Override
	public int updatePhotoShareData(Map<String, String> data) throws DataAccessException {
		return 0;
	}

	@Override
	public int updatePhotoShareDatas(Map<String, String> data) throws DataAccessException {
		return 0;
	}

	@Override
	public int updatePhotoMsgData(Map<String, String> data) throws DataAccessException {
		return 0;
	}

	@Override
	public int addVoiceMsgData(Map<String, String> data) throws DataAccessException {
		return 0;
	}

	@Override
	public int addShopPhotoData(Map<String, String> data) throws DataAccessException {
		return 0;
	}/*
	@Resource
	private UserDAO userDAO;
	@Resource
	private PhotoAlbumDAO photoAlbumDAO;
	@Resource
	private PhotoDAO photoDAO;
	@Resource
	private SharedCardImageDAO sharedCardImageDAO;
	@Resource
	private MessageDAO messageDAO;
	@Resource
	private StoreDAO storeDAO;
	@Resource
	private StoreImageDAO storeImageDAO;

	
	public int updatePhotoHeadData(String userid,Map<String,String> data) throws DataAccessException{
		User user = userDAO.getUserById(Integer.valueOf(userid));
		user.setHeadStatus((short) 1);
		
		if(user.getRegStatus()<6)
			user.setRegStatus((short)6);
		
		//创建相册
		List<PhotoAlbum> photoAlbumList = photoAlbumDAO.getPhotoAlbumByUserId(Integer.valueOf(userid));
		PhotoAlbum photoAlbum = new PhotoAlbum();
		int albumid = 0;
		if(photoAlbumList.size()<=0){
			photoAlbum.setUserId(Integer.valueOf(userid));
			photoAlbum.setName(userid+"1");
			photoAlbum.setPrivacy((short)1);
			photoAlbum.setCreateTime(new Date());
			albumid = photoAlbumDAO.savePhotoAlbum(photoAlbum);
			
			photoAlbum.setAlbumId(albumid);
		}else{
			photoAlbum = photoAlbumList.get(0);
		}

		Photo photo = new Photo();
		photo.setAlbumId(photoAlbum.getAlbumId());
		photo.setUserId(Integer.valueOf(userid));
		photo.setStatus((short)1);
		photo.setPraiseCount(0);
		photo.setCreateTime(new Date());

		//photo.setName(data.get("photoname").replace(".jpg", ""));
		photo.setPhotoUri(data.get("pictureurl"));
		
		int simphotoid = photoDAO.savePhoto(photo);
		
		user.setHeadId(simphotoid);
		userDAO.updateUser(user);
		return simphotoid;
	}


	public int updatePhotoShareDatas(Map<String,String> data) throws DataAccessException
	{
		String url=data.get("pictureurl");
		String[] urls=url.split(",");
		for(int i=0;i<urls.length;i++)
		{
			data.put("pictureurl",urls[i]);
			updatePhotoShareData(data);
		}
		return 0;
	}



	@Override
	public int updatePhotoShareData(Map<String, String> data)
			throws DataAccessException {
		//未审核 1
		int result = 0;
		AlbumImage albumImage = new AlbumImage();
		albumImage.setUserId(Integer.valueOf(data.get("userid")));
		albumImage.setParentId(Integer.valueOf(data.get("shareid")));
		albumImage.setPraiseCount(0);
		albumImage.setStatus((byte)1);
		albumImage.setCreateTime(new Date());
		albumImage.setUri(data.get("pictureurl"));
		
		if(data.get("sharetype").equals("1")){
			SharedCardImage sharedCardImage = new SharedCardImage();
			sharedCardImage.setUserId(Integer.valueOf(data.get("userid")));
			sharedCardImage.setCardId(Integer.valueOf(data.get("shareid")));
			sharedCardImage.setPraiseCount(0);
			sharedCardImage.setStatus((byte) 1);
			sharedCardImage.setUri(data.get("pictureurl"));
			sharedCardImage.setCreateTime(new Date());
			result = sharedCardImageDAO.saveSharedCardImage(sharedCardImage);
			albumImage.setType((byte)2);
		}else if(data.get("sharetype").equals("2")){
			InterestDynamicImage interestDynamicImage = new InterestDynamicImage();
			interestDynamicImage.setUserId(Integer.valueOf(data.get("userid")));
			interestDynamicImage.setDynamicId(Integer.valueOf(data.get("shareid")));
			interestDynamicImage.setPraiseCount(0);
			interestDynamicImage.setStatus((byte) 1);
			interestDynamicImage.setUri(data.get("pictureurl"));
			interestDynamicImage.setCreateTime(new Date());
			result = interestDynamicImageDAO.saveInterestDynamicImage(interestDynamicImage);
			albumImage.setType((byte)1);
		}else if(data.get("sharetype").equals("3")){
			ProductImage productImage = new ProductImage();
			productImage.setImageType(new Short("0"));
			productImage.setCreateTime(Timestamp.valueOf(DateUtils.getCurDateTime()));
			productImage.setStatus(new Short("1"));
			productImage.setUserId(Integer.valueOf(data.get("userid")));
			productImage.setProductId(Integer.valueOf(data.get("shareid")));
			productImage.setBrowseCount(0);
			productImage.setPraiseCount(0);
			productImage.setUri(data.get("pictureurl"));
			return productImageDAO.saveProductImage(productImage);
		}else if(data.get("sharetype").equals("4")){
			ProjectImage projectImage = new ProjectImage();
			projectImage.setImageType(new Short("0"));
			projectImage.setCreateTime(Timestamp.valueOf(DateUtils.getCurDateTime()));
			projectImage.setStatus(new Short("1"));
			projectImage.setUserId(Integer.valueOf(data.get("userid")));
			projectImage.setProjectId(Integer.valueOf(data.get("shareid")));
			projectImage.setBrowseCount(0);
			projectImage.setPraiseCount(0);
			projectImage.setUri(data.get("pictureurl"));
			return projectImageDAO.saveProjectImage(projectImage);
		}else if(data.get("sharetype").equals("5"))
		{
			ExposureImage exposureImage = new ExposureImage();
			exposureImage.setImageType(new Short("0"));
			exposureImage.setCreateTime(Timestamp.valueOf(DateUtils.getCurDateTime()));
			exposureImage.setStatus(new Short("1"));
			exposureImage.setUserId(Integer.valueOf(data.get("userid")));
			exposureImage.setExpId(Integer.valueOf(data.get("shareid")));
			exposureImage.setPraiseCount(0);
			exposureImage.setUri(data.get("pictureurl"));
			return exposureImageDAO.saveExposureImage(exposureImage);
		}
		
		albumImageDAO.saveAlbumImage(albumImage);
		return result;
	}

	@Override
	public int updatePhotoMsgData(Map<String, String> data)
			throws DataAccessException {
		int result = 0;
		Attachment attachment = new Attachment();
		attachment.setCreateTime(new Date());
		attachment.setFileUri(data.get("pictureurl"));
		
		result = attachmentDAO.saveAttachment(attachment);
		
		Message message = new Message();
		if(result>0){
			message.setAttachId(result);
			message.setCreateTime(new Date());
			message.setMsgType((short)2);
			message.setSenderId(Integer.valueOf(data.get("userid")));
			message.setReceiverId(Integer.valueOf(data.get("touserid")));
			message.setStatus((short)0);
			message.setOrigin((short)1);
			result = messageDAO.saveMessage(message);
		}
		
		return result;
	}

	@Override
	public int addVoiceMsgData(Map<String, String> data)
			throws DataAccessException {
		int result = 0;
		Attachment attachment = new Attachment();
		attachment.setCreateTime(new Date());
		attachment.setFileUri(data.get("voiceurl"));
		
		result = attachmentDAO.saveAttachment(attachment);
		
		Message message = new Message();
		if(result>0){
			message.setAttachId(result);
			message.setCreateTime(new Date());
			message.setMsgType((short)3);
			message.setSenderId(Integer.valueOf(data.get("userid")));
			message.setReceiverId(Integer.valueOf(data.get("touserid")));
			message.setText(data.get("time"));
			message.setStatus((short)0);
			message.setOrigin((short)1);
			result = messageDAO.saveMessage(message);
		}
		return result;
	}

	@Override
	public int addShopPhotoData(Map<String, String> data)
			throws DataAccessException {
		String shopid = data.get("shopid");
		if(shopid != null)
		{
			//判断该商铺是否存在
			Store store = storeDAO.getStoreBystoreId(Integer.parseInt(shopid));
			if(store==null)
			{
				return 1;
			}
			StoreImage storeImage = new StoreImage();
			storeImage.setStoreId(Integer.parseInt(data.get("shopid")));
			storeImage.setUri(data.get("shopurl"));
			storeImage.setStatus("0");
			if(!StringUtils.isEmpty(data.get("imagetypeid"))) {
				storeImage.setImageTypeId(Integer.parseInt(data.get("imagetypeid")));
			}
			storeImage.setStoreTypeId(Integer.parseInt(data.get("imgtype")));
			
			return storeImageDAO.saveStroeImage(storeImage);
		}
		return 1;
	}
*/


}
